// custom-tab-bar/index.js

import { storeBindingsBehavior } from 'mobx-miniprogram-bindings'
import { store } from '../store/store'

Component({

  options: {
    styleIsolation: "shared"
  },
  behaviors: [storeBindingsBehavior],
  storeBindings: {
    store,
    fields: {
      active: "activeTabBar",
      goods: "trolleyCount",
    },
    actions: {
      updataActive: "updataActiveTabBar",
      getWebsite: "getWebsite",
    },
  },

  observers: {
    'goods': function (val) {
      this.setData({
        'list[1].info': val,
      })
    }
  },

  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    active: 0,
    list: [
      {
        "pagePath": "/pages/home/home",
        "text": "首页",
        "iconPath": "https://moloo.top/icons/11.png",
        "selectedIconPath": "https://moloo.top/icons/12.png"
      },
      {
        "pagePath": "/pages/trolley/trolley",
        "text": "购物车",
        "iconPath": "https://moloo.top/icons/13.png",
        "selectedIconPath": "https://moloo.top/icons/14.png",
        info : 2
      },
      {
        "pagePath": "/pages/wode/wode",
        "text": "我的",
        "iconPath": "https://moloo.top/icons/15.png",
        "selectedIconPath": "https://moloo.top/icons/16.png"
      }
    ]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onChange(event) {
      // event.detail 的值为当前选中项的索引
      this.setData({ active: event.detail });
      this.updataActive(event.detail);
      wx.switchTab({
        url: this.data.list[event.detail].pagePath,
      })
    },
  }
})
